#pragma once
#include "DXAMLCommon.h"
#include "XamlWriter.h"

class CCoreServices;
class XamlSchemaContext;
struct IPALUri;
struct Xcp_IDependencyObject;
class ObjectWriter;
class XamlReader;
struct IValueStore;
struct IDependencyObject;
class ParserErrorService;
struct XamlQualifiedObject;
class XamlNodeStreamCacheManager;
class XamlTextReaderSettings;
struct IPALResourceManager;
class XamlWriter;

class XamlSavedContext;
class ObjectWriterSettings;

struct IPALStream;

class CParser
{
public: 
	
	//impl
	static HRESULT LoadXaml(CCoreServices * pCore, 
		XUINT32 cSource, 
		XUINT8 * pSource, 
		struct Xcp_IDependencyObject * pEventRoot, 
		struct Xcp_IDependencyObject * pExistingFrameworkRoot, 
		struct Xcp_IDependencyObject * * ppDependencyObject, 
		XINT32 bRequireDefaultNamespace, 
		XUINT32 bAllowEventHandlers, 
		struct Xcp_IDependencyObject * pTemplatedParent, 
		XBOOL bRegisterTemplateItemNames, 
		struct IValueStore * pResourcesForOriginalScope, 
		struct IPALUri * pXamlResourceUri, 
		XUINT32 cSourceAssemblyName, 
		XCHAR * pSourceAssemblyName, 
		XBOOL bExpandTemplatesDuringParse, 
		XBOOL bAllowCoreTypeExistingFrameworkRoot, 
		XUINT32 * puiBinaryXamlCount, 
		XUINT8 * * ppBinaryXaml, 
		XBOOL bRecordToCacheFileOnly, 
		XBOOL bCreateFromCacheFileOnly, 
		const CXString * pstrHashForBinaryXaml);
	
	//impl
	static HRESULT LoadXaml(CCoreServices * pCore, 
		XUINT32 cSource, 
		XUINT8 * pSource, 
		struct Xcp_IDependencyObject * pEventRoot, 
		struct Xcp_IDependencyObject * pExistingFrameworkRoot, 
		struct Xcp_IDependencyObject * * ppDependencyObject, 
		XINT32 bRequireDefaultNamespace, 
		XUINT32 bAllowEventHandlers, 
		struct Xcp_IDependencyObject * pTemplatedParent, 
		XBOOL bRegisterTemplateItemNames,
		XUINT32 cSourceAssemblyName, 
		XCHAR * pSourceAssemblyName, 
		XBOOL bExpandTemplatesDuringParse, 
		XBOOL bAllowCoreTypeExistingFrameworkRoot);

	
	//impl
	static HRESULT CreateFromCacheFile(CCoreServices * pCore, XUINT32 uiBinaryXaml, XUINT8 * pBinaryXaml, xshared_ptr<ObjectWriter> & spObjectWriter, xshared_ptr<XamlSchemaContext> & spXamlSchemaContext);
	
	//impl
	static HRESULT RecordToCacheFile(CCoreServices * pCore, XUINT32 * puiBinaryXaml, XUINT8 * * ppBinaryXaml, xshared_ptr<XamlReader> & spReader, const CXString * pstrHashForBinaryXaml);

	static HRESULT Load(CCoreServices * pCore, xshared_ptr<XamlReader> & spReader, xshared_ptr<XamlSavedContext> &, xshared_ptr<ObjectWriterSettings> &, CDependencyObject * *);
	static HRESULT Transform(CCoreServices * pCore, xshared_ptr<XamlReader> & spReader, xshared_ptr<XamlWriter> &);
protected: 
	
	//impl
	static HRESULT LoadXamlCore( CCoreServices * pCore, 
		XUINT32 cSource, 
		XUINT8 * pSource, 
		struct IPALUri * pXamlResourceUri, 
		struct Xcp_IDependencyObject * pExistingFrameworkRoot, 
		struct Xcp_IDependencyObject * * ppDependencyObject, 
		XINT32 bRequireDefaultNamespace, 
		XUINT32 bAllowEventHandlers, 
		XUINT32 cSourceAssemblyName, 
		XCHAR * pSourceAssemblyName, 
		XBOOL bExpandTemplatesDuringParse, 
		XBOOL bAllowCoreTypeExistingFrameworkRoot, 
		XUINT32 * puiBinaryXamlCount, 
		XUINT8 * * ppBinaryXaml, 
		XBOOL bRecordToCacheFileOnly, 
		XBOOL bCreateFromCacheFileOnly, 
		const CXString * pstrHashForBinaryXaml );

	static HRESULT GetXamlReader(const xshared_ptr<XamlSchemaContext>,XUINT32, XUINT8 *, const CXString &, xshared_ptr<XamlReader> &);
	static HRESULT GetXamlWriter();
private: 

	//impl
	static HRESULT GetAssemblyNameFromUri(xref_ptr<struct IPALUri> spBaseUri, xshared_ptr<CXString> & spAssemblyName);
	
	//impl
	static HRESULT GetAssemblyFromObject(CCoreServices * pCore, struct Xcp_IDependencyObject * pDo, xshared_ptr<CXString> & spAssemblyName);
	
	//impl
	static HRESULT CreateObjectWriter(xshared_ptr<XamlSchemaContext> spSchemaContext, XBOOL fAllowEventHandlers, XBOOL fExpandTemplatesDuringParse, struct IPALUri * pXamlResourceUri, xref_ptr<IPALUri> spBaseUri, struct Xcp_IDependencyObject * pExistingFrameworkRoot, xshared_ptr<ObjectWriter> & spObjectWriter);
	
	//impl
	static HRESULT GetUniqueName(const xref_ptr<struct IPALUri> & spBaseUri, xshared_ptr<CXString> & spUniqueName);
};


